//package cn.zyq.nutlet.system.aspect;
//
//import cn.zyq.nutlet.beans.admin.Admin;
//import cn.zyq.nutlet.beans.userMp.UserMp;
//import cn.zyq.nutlet.service.admin.AdminService;
//import cn.zyq.nutlet.service.userMp.UserMpService;
//import cn.zyq.nutlet.system.annotation.OneClick;
//import cn.zyq.nutlet.system.config.consts.redis.RedisMgtKeys;
//import cn.zyq.nutlet.system.config.consts.redis.RedisMpKeys;
//import cn.zyq.nutlet.system.enums.core.ResponseCodeEnum;
//import cn.zyq.nutlet.system.exception.WebException;
//import cn.zyq.nutlet.system.utils.redis.limit.RequestLimitService;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Method;
//
//@Aspect
//@Component
//public class OneClickAspect {
//    @Autowired
//    private UserMpService userMpService;
//    @Autowired
//    private AdminService adminService;
//    @Autowired
//    private RequestLimitService requestLimitService;
//
//
//    @Pointcut(value = "execution(public * cn.zyq.nutlet.service..*(..))")
//    public void controllerAspect() {
//    }
//
//
//    @Around(value = "controllerAspect()")
//    public Object around(ProceedingJoinPoint pjp) throws Throwable {
//        Method method = AspectUtil.getMethod(pjp);
//        if (method != null && method.isAnnotationPresent(OneClick.class)) {
//            OneClick oneClick = method.getAnnotation(OneClick.class);
//            Object[] args = pjp.getArgs();
//            if (args.length > 0) {
//                Object arg = args[args.length - 1];
//                if (arg instanceof UserMp) {
//                    UserMp userMp = (UserMp) arg;
//                    Boolean flag = this.requestLimitService.limit(RedisMpKeys.ONE_CLICK_KEY(oneClick.scope(), userMp.getUserMpID()), 1, oneClick.timeout());
//                    if (flag) {
//                        throw new WebException(ResponseCodeEnum.ERROR, "操作失败，点击太频繁！");
//                    }
//                } else if (arg instanceof Admin) {
//                    Admin admin = (Admin) arg;
//                    Boolean flag = this.requestLimitService.limit(RedisMgtKeys.ONE_CLICK_KEY(oneClick.scope(), admin.getAdminID()), 1, oneClick.timeout());
//                    if (flag) {
//                        throw new WebException(ResponseCodeEnum.ERROR, "操作失败，点击太频繁！");
//                    }
//                }
//            }
//        }
//        Object result = pjp.proceed();
//        return result;
//    }
//}
